#include "TcpServer.h"

TcpServer::TcpServer(std::string& ip,uint16_t& port)

{

    Socket* servsock = new Socket(createnonblocking());
    InetAddress serveraddr(ip, port);
    servsock->setkeepalive(true);
    servsock->setreuseaddr(true);
    servsock->setreuseport(true);
    servsock->settcpnodelay(true);
    servsock->bind(serveraddr);
    servsock->listen();
    std::vector<epoll_event> evs;

    // int epfd = epoll_create(1);
    // Epoll epoll;
    Channel *servchannel=new Channel(loop_.getEpfd(),servsock->fd());  
    servchannel->setreadcallback(std::bind(&Channel::newConnection,servchannel,servsock));
    servchannel->enablereading(); 
    servchannel->setinepoll();

}

void TcpServer::start()
{
    loop_.run();
}
TcpServer::~TcpServer()
{
    
}